import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.GregorianCalendar;

public class ReaderAndWriter {
    public static void main(String[] args) throws IOException {

            OutputStreamWriter ss = new OutputStreamWriter(new FileOutputStream("src//writer.txt"),"GBK");
        ss.write("中国");
        ss.close();

        InputStreamReader dd = new InputStreamReader(new FileInputStream("src//writer.txt"),"GBK");
        char[]bts =new char[1024];
        int len;
        while ((len=dd.read(bts))!=-1){
            System.out.print(new String(bts,0,len));

        }
        dd.close();
    }
    //字符流复制java文件
    public static void Copy() throws IOException {
        OutputStreamWriter oldone = new OutputStreamWriter(new FileOutputStream("src//reader_demo1.java"),"UTF-8");
        InputStreamReader newone = new InputStreamReader(new FileInputStream("HELLO WORLD//HelloWorld.java"),"UTF-8");
        char[] su =new char[1024];
        int len;
        while ((len=newone.read(su))!=-1){
            oldone.write(su,0,len);

        }
        oldone.close();
        newone.close();

    }
    //字符缓冲流复制java文件
    public static void Copy2() throws IOException {
        BufferedWriter oldone = new BufferedWriter(new FileWriter("src//reader_demo1.java"));
        BufferedReader newone = new BufferedReader(new FileReader("HELLO WORLD//HelloWorld.java"));
        char[] cr =new char[1024];
        int len;
        while ((len=newone.read(cr))!=-1){
            oldone.write(cr,0,len);

        }
        oldone.close();
        newone.close();

    }
    //字符缓冲流复制java文件特有方法（换行读取写入）
    public static void Copy3() throws IOException {
        BufferedWriter oldone = new BufferedWriter(new FileWriter("src//reader_demo1.java"));
        BufferedReader newone = new BufferedReader(new FileReader("HELLO WORLD//HelloWorld.java"));
        String ae;
        while ((ae=newone.readLine())!=null){
            oldone.write(ae);
            oldone.newLine();

        }
        oldone.close();
        newone.close();
    }
    //字符缓冲流复制java文件(字节打印流)
    public static void Copy4() throws IOException {
        PrintWriter oldone = new PrintWriter("src//reader_demo1.java");
        BufferedReader newone = new BufferedReader(new FileReader("HELLO WORLD//HelloWorld.java"));
        String ae;
        while ((ae=newone.readLine())!=null){
           oldone.println(ae);

        }
        oldone.close();
        newone.close();
    }





}
